use std::cmp::min;
use std::io::stdin;

const MAXN: usize = 2000001;

static mut USED: [bool; MAXN] = [false; MAXN];

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
struct Node {
  a: i32,
  num: usize,
  op: i32,
}

fn main() {
  let mut buf = String::new();
  stdin().read_line(&mut buf).unwrap();
  let mut handler = buf.trim().split_ascii_whitespace();
  let n: usize = handler.next().unwrap().parse().unwrap();
  let k: i32 = handler.next().unwrap().parse().unwrap();
  buf.clear();
  stdin().read_line(&mut buf).unwrap();
  handler = buf.trim().split_ascii_whitespace();
  let mut a = Vec::from([Node {
    a: 0,
    num: 0,
    op: 0,
  }]);
  let mut cnt = 1;
  for i in handler {
    a.push(Node {
      a: i.parse().unwrap(),
      num: cnt,
      op: 1,
    });
    cnt += 1;
  }
  buf.clear();
  stdin().read_line(&mut buf).unwrap();
  handler = buf.trim().split_ascii_whitespace();
  for i in handler {
    a.push(Node {
      a: i.parse().unwrap(),
      num: cnt - n,
      op: 0,
    });
    cnt += 1;
  }
  a.sort_unstable();
  let mut l = 0i32;
  let mut r = (n * 2 + 1) as i32;
  let mut now = 0;
  unsafe {
    while (!USED[a[(l + 1) as usize].num]) && now + a[(l + 1) as usize].op <= k {
      now += a[(l + 1) as usize].op;
      USED[a[(l + 1) as usize].num] = true;
      l += 1;
    }
    while (!USED[a[(r - 1) as usize].num]) && now + a[(r - 1) as usize].op <= k {
      now += a[(r - 1) as usize].op;
      USED[a[(r - 1) as usize].num] = true;
      r -= 1;
    }
  }
  let mut ans = 1000000000;
  while l >= 0 {
    ans = min(a[(r - 1) as usize].a - a[(l + 1) as usize].a, ans);
    unsafe {
      USED[a[(l as usize)].num] = false;
    }
    now -= a[(l as usize)].op;
    l -= 1;
    unsafe {
      while (!USED[a[(r - 1) as usize].num]) && now + a[(r - 1) as usize].op <= k {
        now += a[(r - 1) as usize].op;
        USED[a[(r - 1) as usize].num] = true;
        r -= 1;
      }
    }
  }
  print!("{}", ans);
}
